local skel = fk.CreateSkill {
  name = "emo__luoai",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__luoai"] = "落哀",
  [":emo__luoai"] = "锁定技，每当你从弃牌堆以外的区域获得牌后，你将这些牌置入弃牌堆，再从弃牌堆随机获得等量+1张非本回合进入的牌。",
}

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(skel.name) then return end
    local ids = {}
    for _, move in ipairs(data) do
      if move.toArea == Card.PlayerHand and move.to == player then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea ~= Card.DiscardPile and table.contains(player.player_cards[Player.Hand], info.cardId) then
            table.insert(ids, info.cardId)
          end
        end
      end
    end
    ids = player.room.logic:moveCardsHoldingAreaCheck(ids)
    if #ids > 0 then
      event:setCostData(self, ids)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local throw = event:getCostData(self)
    room:moveCardTo(throw, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name, nil, true)
    if player.dead then return end
    local record = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(record, info.cardId)
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    local pile = table.filter(room.discard_pile, function (id)
      return not table.contains(record, id)
    end)
    if #pile == 0 then return end
    room:delay(200)
    local get = table.random(pile, #throw + 1)
    room:obtainCard(player, get, false, fk.ReasonPrey, player, skel.name)
  end,
})

return skel
